package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"group-card/common/constant"
	"group-card/model/entity"
	"group-card/rpc/sys/internal/svc"
	"group-card/rpc/sys/sysclient"
)

type CustomerFindOneLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCustomerFindOneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CustomerFindOneLogic {
	return &CustomerFindOneLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CustomerFindOneLogic) CustomerFindOne(in *sysclient.CustomerFindOneRequest) (*sysclient.CustomerFindOneResponse, error) {
	var ctx context.Context
	data, err := l.svcCtx.CustomerModel.FindOne(ctx, &entity.SysCustomerReq{
		Id: in.Id,
	})
	if err != nil {
		return nil, err
	}

	customer := &sysclient.CustomerFindOneResponse{
		Id:            data.Id,
		Name:          data.Name,
		MobilePhone:   data.MobilePhone,
		LandlinePhone: data.LandlinePhone,
		Area:          data.Area,
		Address:       data.Address,
		Email:         data.Email,
		BeginTimes:    data.BeginTimes.Format(constant.YMDHIS),
		EndTimes:      data.EndTimes.Format(constant.YMDHIS),
		Status:        data.Status,
		CreateAt:      data.CreateAt.Format(constant.YMDHIS),
		UpdateAt:      data.UpdateAt.Format(constant.YMDHIS),
		DeleteAt:      data.DeleteAt.Format(constant.YMDHIS),
	}

	return customer, nil
}
